$(function(){
	    $("#userinfo td").not($("#filter_ke td")).addClass("info_td1");
		$("#userinfo tr").find("td:even").not($("#filter_ke td")).addClass("title_info2");
		$("#userinfo tr").find("td:odd").not($("#filter_ke td")).css("padding-left","5px");
});

function bigCategoryChange(){
	var bigCategoryValue = $("#bigCategory option:selected").val();
	if(bigCategoryValue != ""){
		$('#smallCategory').html('加载中... ...');
		$('#goods').html('');
		$('#goodsType').html('');
		cacheData = '';
		$.get('../category/category_loadCategoryByPid.shtml?id='+bigCategoryValue+'&t='+new Date().getTime().toString(36),function(mes){
			var json = eval('('+mes+')');
			var str = '<select name="categoryId" id="categoryId" onchange="smallCategoryChange();" ><option value="">请选择</option>';
			for(var i = 0; i < json.length; i++){
				str += '<option value="'+json[i]['id']+'">'+json[i]['name']+'</option>';
			}
			str+='</select>';
			$('#smallCategory').html(str);
		})
	}
}

var cacheData;
function smallCategoryChange(){
	var smallCategoryValue = $("#categoryId option:selected").val();
	if(smallCategoryValue != ""){
		$('#goodsType').html('加载中... ...');
		$.get('../type/type_loadTypeByCategoryId.shtml?categoryId='+smallCategoryValue+'&t='+new Date().getTime().toString(36),function(mes){
			var json = eval('('+mes+')');
			var str = '<select name="typeId" id="typeId" onchange="threechange();" ><option value="">请选择</option>';
			for(var i = 0; i < json.length; i++){
				str += '<option value="'+json[i]['id']+'">'+json[i]['name']+'</option>';
			}
			str+='</select>';
			$('#goodsType').html(str);
		})
		$('#goods').html('加载中... ...');
		$.get('../brand/findAllBrandByCategory.shtml?categoryId='+smallCategoryValue+'&t='+new Date().getTime().toString(36),function(mes){
			var json = eval('('+mes+')');
			var str = '<select name="brandId" id="brandId"><option value="">请选择</option>';
			for(var i = 0; i < json.length; i++){
				str += '<option value="'+json[i]['id']+'">'+json[i]['name']+'</option>';
			}
			str+='</select>';
			cacheData = str;
			$('#goods').html(str);
		})
	}
}
function threechange(){
	var value2 = $("#typeId option:selected").val();
	if(value2==undefined)value2='';
	if(value2 != ""){
		$('#goods').html('加载中... ...');
		$.get('../brand/findAllBrandByType.shtml?typeId='+value2+'&t='+new Date().getTime().toString(36),function(mes){
			var json = eval('('+mes+')');
			var str = '<select name="brandId" id="brandId"><option value="">请选择</option>';
			for(var i = 0; i < json.length; i++){
				str += '<option value="'+json[i]['id']+'">'+json[i]['name']+'</option>';
			}
			str+='</select>';
			$('#goods').html(str);
		})
	}else{
		$('#goods').html(cacheData);
	}
}

/**
 * 验证写字楼修改需求信息
 */
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
// 为true不等于空
function checkNull(obj) {
	if (obj.value.trim().length == 0 || obj.value == 0.0)
		return false;
	else
		return true;
}

function checkLength(obj, len) {
	if (obj.value.length > len)
		return true;
	else
		return false;
}

// 判断是否是非正浮动数
function isFloat(obj) {
	var reg = /^((-\d+(\.\d+)?)|(0+(\.0+)?))$/
	if (reg.test(obj.value)) {
		return true;
	} else {
		return false;
	}
}
// 判断是正实数 不是则用空字符串代替
function isNum(obj) {
	if (isNaN(obj.value)) {
		obj.value = "";
	}
	if (isFloat(obj)) {
		obj.value = "";
	}

}

function checkmodify() {

	
	var name = document.getElementById("name");
	if ((!checkNull(name))) {
		alert("请先填写商品名称");
		name.focus();
		return false;
	}
	var bigCategory = document.getElementById("bigCategory");
	if ((!checkNull(bigCategory))) {
		alert("请选择类别");
		bigCategory.focus();
		return false;
	}
	var categoryId = document.getElementById("categoryId");
	if ((!checkNull(categoryId))) {
		alert("请选择子类别");
		categoryId.focus();
		return false;
	}
	var brandId = document.getElementById("brandId");
	if ((!checkNull(brandId))) {
		alert("请选择选择符合的产品");
		brandId.focus();
		return false;
	}
	var price = document.getElementById("price");
	if (!checkNull(price)) {
		alert("请填写原价");
		price.focus();
		return false;
	}
	
	
	var upprice = document.getElementById("upprice");
	if (!checkNull(upprice)) {
		alert("请填写抢购价");
		upprice.focus();
		return false;
	}
	/**var units = document.getElementById("units");
	if (!checkNull(units)) {
		alert("请填写单位");
		units.focus();
		return false;
	}**/
	var overTime=document.getElementById("overTime");
	if(!checkNull(overTime)){
           alert('请选择抢购结束时间');
           overTime.focus();
           return false;
     }
     var img = document.getElementById("img");
     if(img!=null) 
     if(img.value!='')
     if(!/(.gif)|(.png)|(.jpg)|(.jpeg)|(.ico)$/.exec(img.value)){
		alert('请上传图片格式文件');
		return false;
	}
	var statement = document.getElementById("statement");
	if (!checkNull(statement)) {
		alert("请填写抢购声明");
		statement.focus();
		return false;
	}
	if(checkLength(statement,200))
	{
	   alert("抢购声明输入已超过200个字");
	   statement.focus();
	   return false;
	}
    // if (!KE.util.isEmpty('content')) document.getElementById("content").value=KE.util.getData('content');
	if (confirm("确认保存商品信息吗?"))
		return true;
	return false;
}
   function  modifyPic(id){
       $("#modifyPic").html('<input type="file" name="imgcomp" id="img"/>&nbsp;&nbsp;&nbsp;<input type="button" value="取消" onclick="movePic()"/>');
       $("#"+id).hide();
   }
   function  movePic(){
      var picbtn=document.getElementById("picbtn");
      $("#modifyPic").html('');
      picbtn.style.display='inline';
   }
  	
   function  modifyPic1(id){
       $("#modifyPic").html('<input type="file" name="imgcomp1" id="img"/>&nbsp;&nbsp;&nbsp;<input type="button" value="取消" onclick="movePic1()"/>');
       $("#"+id).hide();
   }
   function  movePic1(){
      var picbtn=document.getElementById("picbtn1");
      $("#modifyPic1").html('');
      picbtn.style.display='inline';
   }
